package com.entity;

import com.utils.ToCamelCaseUtil;

import org.apache.ibatis.io.Resources;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import lombok.Data;

/**  */
@Data
@PropertySource(value = "classpath:defaultNoticeTemplate.properties", encoding = "UTF-8")
public class Notice {

  /** 通知类型 */
  public static final int GOOD_REPORT = 1;

  public static final int DISAGREE_GOOD_REPORT = 2;
  public static final int AGREE_GOOD_REPORT = 3;
  public static final int GOOD_UNQUALIFIED_REMIND = 4;
  public static final int GOOD_UNQUALIFIED_WARNING = 5;
  public static final int CANCEL_SELL_PERMISSION = 6;
  public static final int COMMENT_REPORT = 11;
  public static final int DISAGREE_COMMENT_REPORT = 12;
  public static final int AGREE_COMMENT_REPORT = 13;
  public static final int COMMENT_UNQUALIFIED_REMIND = 14;
  public static final int COMMENT_UNQUALIFIED_WARNING = 15;
  public static final int CANCEL_COMMENT_PERMISSION = 16;
  public static final int GOOD_BE_COMMENTED = 20;
  public static final int WITHDRAW_COMMIT = 30;
  public static final int WITHDRAW_SUCCESS = 31;
  public static final int BUY_COIN_SUCCESS = 33;
  public static final int ORDER_TIMEOUT = 40;
  public static final int ORDER_PAY_SUCCESS = 41;
  public static final int CONFIRM_GOODS_OFFLINE = 42;
  public static final int START_DELIVERY = 43;
  public static final int BUYER_PAY_SUCCESS = 50;
  public static final int PUT_OFF_GOOD_BECAUSE_OF_STORE = 51;
  public static final int BUYER_CONFIRM_GOODS = 52;
  public static final int URGED_DELIVERY = 53;
  public static final int FEEDBACK = 60;
  private static final HashMap<Integer, String> NoticeTemplate = new HashMap<>(50);

  static {
    Properties pro = new Properties();
    try {
      InputStream is = Resources.getResourceAsStream("defaultNoticeTemplate.properties");
      pro.load(new InputStreamReader(is, StandardCharsets.UTF_8));
    } catch (IOException e) {
      e.printStackTrace();
    }
    Class<Notice> nc = Notice.class;
    pro.forEach(
        (k, v) -> {
          try {
            NoticeTemplate.put(
                (Integer) nc.getField(ToCamelCaseUtil.toCamelCase((String) k)).get(nc), (String) v);
          } catch (Exception e) {
            System.out.println(k + "找不到对应的值");
          }
        });
  }

  private String id;
  private Date time;
  private int kind;
  private int status;
  private String template;
  private Map<String, Object> param;

  public static String getDefaultTemplate(int kind) {
    return NoticeTemplate.get(kind);
  }
}
